//
//  LiPaiTypeView.m
//  WatermarkCamera
//
//  Created by zhibao on 2023/9/20.
//

#import "LianPaiTypeView.h"
@interface LianPaiTypeView(){

}
@end
@implementation LianPaiTypeView
- (instancetype)initWithType:(LiPaiType)selectType{
    if(selectType == LiPaiTypeDanPai){
        self = [super initWithFrame:CGRectMake(0, 0, 17 * 2, 20)];
    }else if(selectType == LiPaiTypeShuangPai){
        self = [super initWithFrame:CGRectMake(0, 0, 17 , 20 * 2)];
    }else if(selectType == LiPaiTypeSi){
        self = [super initWithFrame:CGRectMake(0, 0, 17 * 2, 20 * 2)];
    }else if(selectType == LiPaiTypeLiu){
        self = [super initWithFrame:CGRectMake(0, 0, 17 * 3, 20 * 2)];
    }else if(selectType == LiPaiTypeJiu){
        self = [super initWithFrame:CGRectMake(0, 0, 17 * 3, 20 * 3)];
    }
    
    if(self){
        self.type = selectType;
        [self initView];
    }
    return self;
}

-(void)initView{
    if(self.type == LiPaiTypeDanPai){
        for (int i = 0; i < 2; i ++) {
            UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(17 * i, 0, 17, 20)];
            tempView.layer.borderColor = UIColor.whiteColor.CGColor;
            tempView.layer.borderWidth = 0.5;
            tempView.tag = 1000 + i;
            tempView.backgroundColor = MyColorAlpha(@"ffffff", 0.4);
            [self addSubview:tempView];
        }
    }else if(self.type == LiPaiTypeShuangPai){
        for (int i = 0; i < 2; i ++) {
            UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(0, 20 * i, 17, 20)];
            tempView.layer.borderColor = UIColor.whiteColor.CGColor;
            tempView.layer.borderWidth = 0.5;
            tempView.tag = 1000 + i;
            tempView.backgroundColor = MyColorAlpha(@"ffffff", 0.4);
            [self addSubview:tempView];
        }
    }else if(self.type == LiPaiTypeSi){
        for (int i = 0; i < 2; i ++) {
            for (int j = 0; j < 2; j ++) {
                UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(17 * j, 20 * i, 17, 20)];
                tempView.layer.borderColor = UIColor.whiteColor.CGColor;
                tempView.layer.borderWidth = 0.5;
                tempView.tag = 1000 + i * 2 + j;
                DLog(@"tag == %d",1000 + i * 2 + j);
                tempView.backgroundColor = MyColorAlpha(@"ffffff", 0.4);
                [self addSubview:tempView];
            }
        }
    }else if(self.type == LiPaiTypeLiu){
        for (int i = 0; i < 2; i ++) {
            for (int j = 0; j < 3; j ++) {
                UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(17 * j, 20 * i, 17, 20)];
                tempView.layer.borderColor = UIColor.whiteColor.CGColor;
                tempView.layer.borderWidth = 0.5;
                tempView.tag = 1000 + i * 3 + j;
                tempView.backgroundColor = MyColorAlpha(@"ffffff", 0.4);
                [self addSubview:tempView];
            }
        }
    }else if(self.type == LiPaiTypeJiu){
        for (int i = 0; i < 3; i ++) {
            for (int j = 0; j < 3; j ++) {
                UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(17 * j, 20 * i, 17, 20)];
                tempView.layer.borderColor = UIColor.whiteColor.CGColor;
                tempView.layer.borderWidth = 0.5;
                tempView.tag = 1000 + i * 3 + j;
                tempView.backgroundColor = MyColorAlpha(@"ffffff", 0.4);
                [self addSubview:tempView];
            }
        }
    }
    
    UILabel *label = [UILabel new];
    label.text = LocalizedString(@"连续拍照，合成一张");
    label.font = MY_SCALE_SemiboldFONT(14);
    label.textColor = UIColor.whiteColor;
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.mas_bottom).offset(3);
    }];
}

- (void)updata:(int)num{
    for (int i = 0; i < 9; i ++) {
        UIView *tempView = [self viewWithTag:1000 + i];
        if(tempView){
            tempView.backgroundColor = MyColorAlpha(@"ffffff", 0.4);
        }
    }
    for (int i = 0; i < num; i ++) {
        UIView *tempView = [self viewWithTag:1000 + i];
        tempView.backgroundColor = MyColor(@"#12BFFF");
    }
}

@end
